import { Component, OnInit } from '@angular/core';
import { InitDataPipe } from 'src/app/base/pipe/initdata.pipe';
import {NzModalService} from "ng-zorro-antd";
declare var form: any;
declare var security: any;

@Component({
  templateUrl: './air.component.html'
})
export class AirComponent implements OnInit {

  ss: any;
  // 表单
  fs: any = null;
  ffs: any;
  // 字典
  airportDic: any = null;
  constructor(private initdataPipe: InitDataPipe, private modal: NzModalService) {
    this.ss = security.SecurityService;
    this.ss.show = false;
    this.ffs = new form.FileService();
    this.fs = new form.FormSimpleService('temporaryair', {
      orderObject: { id: 0 },
      keyField: 'id',
      randomFields: ['id'],
      // 加入导入配置中的配置编号
      inputid: 'kzangz',
      // Excel中导入数据的开始行(第一行为0)
      startrow: 1
    });

    this.fs.loadData(true, (data) => {
      if (this.fs.er.airport === undefined) {
        this.fs.er.airport =  this.ss.user.userDepCode[0];
      }

    });

    this.airportDic = new form.DictionaryService('zd_airport');
    this.airportDic.loadAll();
  }

  ngOnInit() {
  }
  addRow() {
    this.initdataPipe.transform(this.fs.er, 'temp-air');
    this.fs.addRow(this.fs.er);
  }
  // 文件上传后处理
  excelHandleChange(obj) {
    this.fs.excelHandleChange(obj, () => {
      this.fs.loadData(true);
      this.modal.success({
        nzTitle: '系统提示',
        nzContent: '数据导入成功'
      });
    }, () => {
      this.modal.error({
        nzTitle: '系统提示',
        nzContent: '数据导入失败，详细请查看数据导入日志！'
      });
    });
  }
}
